/*****************************************************************************************************************
* File:SystemB.java
*
* Description:
*
* This class contains the entry point for System B, the main method which instantiates the filters 
* required for the system to run. It calls the connect method from FilterFramework2 to connect
* the ports of the filters together. It is used to set the parameters and to structure the pipe
* and filter system. Once the entire system is set up, a thread is started for each of the filters
*
* Parameters: 		Source File name
*
*@author Team 10
*
******************************************************************************************************************/
public class SystemB extends SystemSuperClass
{
   public static void main( String argv[])
   {
		/****************************************************************************
		* Here we instantiate three filters.
		****************************************************************************/
	   String filename = null;
	   try
	   {
		   //setting the filename to the command line argument.
	   filename = argv[0];
	   
	   } 	catch (ArrayIndexOutOfBoundsException e){
			System.out.println("Correct Usage: java SystemB <sourcefile>");   //printing the correct usage of the command
			System.exit(1);
		}
	   
	   //This static method call determines the frame length to handle the case
	   //when different files have varying frame lengths
	   
	    determineFrameLength(filename);
	    
		/****************************************************************************
		* Here we instantiate the filters needed for System B
		****************************************************************************/
	   
	    SourceFilter sourceFilter = new SourceFilter(filename); //Source filter that reads from file
		AltitudeFilter altFilter=new AltitudeFilter();          //Altitude filter to convert from feet to meters
		TemperatureFilter tempFilter=new TemperatureFilter();	//Temperature Filter to convert from Fahrenheit to Celsius
		SplitterFilter splitter = new SplitterFilter();			//Splitter to split the stream of data into two copies
		PressureWPFilter pressureFilter = new PressureWPFilter(80, 50);  //Pressure Filter that takes the range to calculate wild points
		SuperSinkFilter superSink = new SuperSinkFilter(
				new int[]{0,4,2,3},											//SuperSink, a sink filter that writes clean data to one file
				new int[]{0,3},												// and wild point data to another
				"OutputB.dat", "WildPoints.dat", 3);
		
		
		/****************************************************************************
		* Connecting the filters together
		****************************************************************************/	
		
			
		altFilter.Connect(sourceFilter, 0, 0);		//Connects output port of source filter to altitude filter 
		tempFilter.Connect(altFilter, 0, 0);		//Connects output port of altitude filter to input port of temperature filter
		splitter.Connect(tempFilter, 0, 0);			 //Connects output port of Temperature Filter to Splitter
		pressureFilter.Connect(splitter, 0, 0); 	 //Connects First output port of splitter to pressure filter
		superSink.Connect(pressureFilter, 0, 0);	 //Connects output port of pressure filter to first input port of superSink
		superSink.Connect(splitter, 1, 1);           //Connects  Second output port of splitter to second input port of superSink.

		/****************************************************************************
		* Starting threads for each of the Filters
		****************************************************************************/	
		
		sourceFilter.start();
		altFilter.start();
		tempFilter.start();
		pressureFilter.start();
		splitter.start();
		superSink.start();

		
   } // main

} // System B